﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SkillArrow : MonoBehaviour
{
	public Transform endTran;
	public float factor = 1;
	public Renderer line;
	private Vector3 end;
	private Vector3 start;
	private float yScale = 1;
	
	
	public void SetStart(float x,float y,float z)
	{
		start.Set(x, y, z);
	}
	public void SetEnd(float x,float y,float z)
	{
		end.Set(x, y, z);
	}
	public void SetYScale(float scale)
	{
		yScale = scale;
	}
	public void UpdateLine()
	{
		transform.position = start;
		var dir = end - start;
		dir.y = 0;
		float dis = dir.magnitude;
		transform .localScale = new Vector3(dis * factor, yScale, transform.localScale.z);
		line.material.SetTextureScale("_MainTex", new Vector2(dis, 1));
		transform.right = -dir;  
	}
#if UNITY_EDITOR
	void Update()
    {
		if(endTran != null)
		{
			var p = endTran.position;
			SetEnd(p.x,p.y,p.z);
			UpdateLine();
		}
    }
#endif
}
